import profile
import helpers.FileHelper as FileHelper
import helpers.GUIHelper as GUIHelper
from PIL import Image



image_filter = FileHelper.SuffixFilter({"jpg", "jpeg", "png"})


def check(root_path):
    def callback(file_path, dirname, filename):
        img = Image.open(file_path)
        limit = profile.effect_max_image_size
        w = img.size[0]
        h = img.size[1]
        if w > limit or h > limit:
            info = "{}:{}x{}\n图片尺寸过大\nyes: skip\n no: ignore".format(filename, w, h)
            if GUIHelper.ask_continue3("WARNING", info):
                return True
    FileHelper.filter_dir(root_path, [image_filter], callback)